# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Maintainer: Alad Wenter <alad@mailbox.org>
# Contributor: Gavin Lloyd <gavinhungry@gmail.com>
# Contributor: Timothy Rice <timothy.rice@unimelb.edu.au>

pkgname=datamash
pkgver=1.8
pkgrel=1
pkgdesc='Performs basic numeric, textual and statistical operations on input textual data files'
arch=('loong64' 'x86_64')
url='https://www.gnu.org/software/datamash'
license=('GPL')
source=("https://ftp.gnu.org/gnu/$pkgname/$pkgname-$pkgver.tar.gz"
        "https://ftp.gnu.org/gnu/$pkgname/$pkgname-$pkgver.tar.gz.sig")
sha512sums=('5ef312a73ebee5df7308b7e368f296714fcc396761499d4a5ba94906f6ecdb0867193c5ce25668bf56b7a5339a8a833a98b3ad564c01544880a6ec210c7b922a'
            'SKIP')
b2sums=('42ca3528dd8011961a6711054177e263c7ad4f429f40db0532719134ff1d735b5424dcd6d2643df123d9994df7d4ceb5b36578af5a86b4070a879eebea940c73'
        'SKIP')
validpgpkeys=('33382C8D62017A1012A05B35BDB72EC3D3F87EE6') # Timothy Rice (Yubikey 5 Nano 13139911) <trice@posteo.net>

build() {
  cd "$pkgname-$pkgver"

  ./configure --prefix=/usr

  make
}

check() {
  cd "$pkgname-$pkgver"

  make check
}

package() {
  cd "$pkgname-$pkgver"

  make DESTDIR="$pkgdir" install

  # ensure bash completions go to correct directory
  install -vd "$pkgdir/usr/share/bash-completion/completions"
  mv -v "$pkgdir/usr/share/datamash/bash-completion.d/$pkgname" \
    "$pkgdir/usr/share/bash-completion/completions"

  # move documentation to correct directory
  install -vd "$pkgdir/usr/share/doc"
  mv -v "$pkgdir/usr/share/$pkgname" "$pkgdir/usr/share/doc"

  # remove empty folder
  rm -vrf "$pkgdir/usr/share/datamash"
}
